package com.xpert.dao;

import java.sql.SQLException;
import java.util.ArrayList;

import com.xpert.beans.Board;

public class BoardDao extends CommonDao {
  public static BoardDao getInstance() {
  	BoardDao _instance = new BoardDao();
  	_instance.setDB();
  	return _instance;
  }
  
  /*
   * SqlMapExecutor.queryForList() : for the select query that returns more than one row
   * first param addresses the id of the sql(ex. the id of board.xml)
   * second is for the condition of the WHERE clause of SELECT sentence. Must be object type of any kind
   * 
   * SqlMapExecutor.queryForList(id, parameterObject, skip, max)
   * third - page number, fourth - number of rows to get
   * 
   */
  @SuppressWarnings("unchecked")
  public ArrayList<Board> getArticleList(int page) throws SQLException {
    ArrayList<Board> articleList = (ArrayList<Board>)getDB().queryForList("getArticleList", null, page, 10);
    	return articleList;
  }
    
  public Board getArticle(int idx) throws SQLException {
  	Board articleDetail =(Board)getDB().queryForObject("getArticle", idx);
  	return articleDetail;
  }
  
  public int setArticleCount(Board board) throws SQLException {
  	int success = getDB().update("setArticleCount", board);
  	return success;
  }
    
  public void insertArticle(Board board) throws SQLException {
  		getDB().insert("insertArticle", board);
  }
  
  public Board modifyArticle(int idx) throws SQLException {
  	Board articleDetail = (Board)getDB().queryForObject("getArticle", idx);
  	return articleDetail;
  }
  
  public void modifyArticleProc(Board board) throws SQLException {
  	getDB().update("updateArticle", board);
  }
  
  public void deleteArticle(int idx) throws SQLException {
  	getDB().delete("deleteArticle", idx);
  }

}
